package com.gimi.cloud.jimi.client.service.userInfo.impl;

import com.gimi.cloud.jimi.client.service.userInfo.TaobaoService;
import com.gimi.cloud.jimi.dao.dao.userInfo.RdTaobaoDao;
import com.gimi.cloud.jimi.dto.userInfo.RdTaobaoDTO;
import com.gimi.cloud.jimi.entity.userInfo.RdTaobao;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TaobaoServiceImpl implements TaobaoService {
    @Autowired
    private RdTaobaoDao rdTaobaoDao;

    @Override
    public void saveTaobao(RdTaobaoDTO taobaoDTO) {
        RdTaobao taobao = new RdTaobao();
        BeanUtils.copyProperties(taobaoDTO, taobao);
        if(taobao.getTbId() != null && taobao.getTbId().intValue() > 0) {
            rdTaobaoDao.updateByPrimaryKey(taobao);
        } else {
            rdTaobaoDao.baseInsert(taobao);
        }
    }

    @Override
    public RdTaobaoDTO getNewestTaobaoByUser(Integer userId) {
        RdTaobao taobao = rdTaobaoDao.getNewestTaobaoByUser(userId);
        if(taobao != null) {
            RdTaobaoDTO dto = new RdTaobaoDTO();
            BeanUtils.copyProperties(taobao, dto);
            return dto;
        }
        return null;
    }
}
